#include "TripBox.h"


TripBox::TripBox(int x, int y, bool czy_staly, int index_x,int index_y,int L, int R, int U, int D)
{
    pole::y = x;
    pole::x = y;
    pole::czy_staly = czy_staly;
    pole::index_tablicy_x = index_x;
    pole::index_tablicy_y = index_y;
    obrazek = NULL;
    AnimBuff = NULL;
    pole::PlayerOnSquer=-1;
    wektor = new wektory(L,R,U,D);
    frame = 0;
    TypeOfBox=1;
    TypeOfTrip=0;
    Rectangle = new SDL_Rect[4];
    for(int i=0; i<4; i++)
    {
        Rectangle[i].x =i*POLE_SIZE_PX;
        Rectangle[i].y =0;
        Rectangle[i].h = POLE_SIZE_PX;
        Rectangle[i].w = POLE_SIZE_PX;

    }
   Position.x = y ;
   Position.y = x ;
   Position.w = POLE_SIZE_PX ;
   Position.h = POLE_SIZE_PX;



}
TripBox::~TripBox()
{

}



void TripBox::animuj(SDL_Surface* screen)
{
 if(PlayerOnSquer==0 || PlayerOnSquer==1 ) //Jeśli player 1 lub player 2 jest na polu to animuje
 {
  if(frame>3)
    frame = 0;
  SDL_BlitSurface(AnimBuff,&Rectangle[frame],screen,&Position);
  frame++;
  SDL_Delay(30);
 }
 else
 {
     SDL_BlitSurface(AnimBuff,&Rectangle[3],screen,&Position);
 }

}
void TripBox::wczytaj_animacje()
{
        //wczyta do buffora bitmapy do animacja dla kazdej struc ;] raz a dobrze a co tam ! :D
}
void TripBox::rysuj_postac_na_polu()
{
  // wsk->rysuj(10);
}
int TripBox::czy_dozwolony_ruch(int x, int y)
{
       //Na co to hmmmmmmmmmmmmmmmmmmmm ?? Chyba Jacusiu masz juz to zaimplementowne u siebie :P
}

void TripBox::LoadTrip()
{
  srand(time(NULL));
  int liczba;
  liczba = rand()%100;
  if(liczba<25)
  {
    AnimBuff = SDL_DisplayFormat(SDL_LoadBMP("grafika/trip.bmp"));
    TypeOfTrip=2;
  }
  if(liczba>=25 && liczba < 50)
  {
    AnimBuff = SDL_DisplayFormat(SDL_LoadBMP("grafika/trip2.bmp"));
    TypeOfTrip=3;
  }
  if(liczba>=50 && liczba < 75 )
  {
     AnimBuff = SDL_DisplayFormat(SDL_LoadBMP("grafika/trip3.bmp"));
     TypeOfTrip=1;
  }
  if(liczba>=75 )
  {
    AnimBuff = SDL_DisplayFormat(SDL_LoadBMP("grafika/trip4.bmp"));
    TypeOfTrip=4;
  }

  if(AnimBuff == NULL)
    exit(-1);
 SDL_SetColorKey(AnimBuff, SDL_SRCCOLORKEY, SDL_MapRGB( AnimBuff->format, 255, 0 , 255 ) );
}
Uint32 TripBox::TimeLeft(void){
    static Uint32 next_time = 0;
    Uint32 now;

    now = SDL_GetTicks();
    if ( next_time <= now ) {
        next_time = now+TICK_INTERVAL;
        return(0);
    }
    return(next_time-now);
}

void TripBox::MoveTrip(int way, int i)
{
    if(way==1) // W lewo
    {
        Position.x -=POLE_SIZE_PX/i;
    }
    if(way==2) // W prawo
    {
        Position.x +=POLE_SIZE_PX/i;
    }
    if(way==3) // W góre
    {
        Position.y -=POLE_SIZE_PX/i;
    }
     if(way==4) // W dół
    {
        Position.y +=POLE_SIZE_PX/i;
    }
}
void TripBox::WypiszWektoryDoPliku()
{
     wektor->printVector();
}
